package com.wangtianxiang.sxp.weixin.utils;

import com.alibaba.fastjson.JSON;
import com.wangtianxiang.sxp.cache.utils.RedisUtil;
import com.wangtianxiang.sxp.po.WxUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Component
public class LoginUtils {

    @Autowired
    private RedisUtil redisUtil;

    public WxUser getUser(){
        ServletRequestAttributes servletRequestAttributes =  (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        String authToken = request.getHeader("Authorization");
        return JSON.parseObject((String) redisUtil.get(authToken),WxUser.class);
    }
}
